package com.cndw.kungfu.dao;

import java.util.List;

import com.cndw.dao.jade.annotation.DAO;
import com.cndw.dao.jade.annotation.SQL;
import com.cndw.dao.jade.annotation.SQLParam;
import com.cndw.kungfu.domain.Player;
import com.cndw.kungfu.domain.Union;
import com.cndw.kungfu.model.disciple.domain.Disciple;
import com.cndw.kungfu.vo.rankingvo.PlayerRankingVO;

@DAO
public interface RankingListDao {

	public static final String PLAYER_RANKING_TABLE = " kf_player_ranking ";
	public static final String PLAYER_RANKING_FIELD = "playerId,levelRank,attackRank,discipleRank,unionRank,collectRank,towerRank,updateTime";

	// ======================= 个人排名 =================================

	@SQL("select " + PLAYER_RANKING_FIELD + " from" + PLAYER_RANKING_TABLE + "where playerId=:playerId")
	public PlayerRankingVO getPlayerRanking(@SQLParam("playerId") long playerId);

	@SQL("insert into " + PLAYER_RANKING_TABLE + " (" + PLAYER_RANKING_FIELD
			+ ") values(:r.playerId,:r.levelRank,:r.attackRank,:r.discipleRank,:r.unionRank,:r.collectRank,:r.towerRank,UNIX_TIMESTAMP())")
	public void addPlayerRanking(@SQLParam("r") PlayerRankingVO playerRanking);

	@SQL("update "
			+ PLAYER_RANKING_TABLE
			+ "set levelRank=:r.levelRank,attackRank=:r.attackRank,discipleRank=:r.discipleRank,unionRank=:r.unionRank,collectRank=:r.collectRank,towerRank=:r.towerRank,updateTime=UNIX_TIMESTAMP() where playerId=:r.playerId")
	public void updatePlayerRanking(@SQLParam("r") PlayerRankingVO playerRanking);

	// ======================= 系统排名 =================================
	@SQL("select playerId,playerName,level,vocationId,level from " + PlayerDao.TABLE + " where level >= 8 order by level desc,exp desc limit 0,100 ")
	public List<Player> getLevelRanking();

	@SQL("select playerId,playerName,level,vocationId,score from " + PlayerDao.TABLE + " where level >= 8 order by score desc,regTime limit 0,100 ")
	public List<Player> getAttackRanking();

	@SQL("select playerId,playerName,level,vocationId,points from " + PlayerDao.TABLE + " where level >= 8 and points > 0 order by points desc,regTime limit 0,100 ")
	public List<Player> getCollectRanking();

	@SQL("select playerId,sum(score)as score,max(score)as maxScore,min(createTime) from " + DiscipleDao.TABLE
			+ " where campId > 0 group by playerId order by score desc,maxScore desc,createTime limit 0,100 ")
	public List<Disciple> getDiscipleRanking();

	@SQL("select id,playerId,name,level,asset,resource,memberCount from " + UnionDao.UNION_TABLE + " order by level desc,asset desc,resource desc,memberCount desc,addTime limit 0,100 ")
	public List<Union> getUnionRanking();

}
